Skip to content

fix(mcp): guard nil initializeParams on id:null with new-protocol _meta#1048

Closed
kuangmi-bit wants to merge 1 commit into
modelcontextprotocol:mainfrom
kuangmi-bit:fix/1043-null-id-panic
Closed

fix(mcp): guard nil initializeParams on id:null with new-protocol _meta#1048
kuangmi-bit wants to merge 1 commit into
modelcontextprotocol:mainfrom
kuangmi-bit:fix/1043-null-id-panic

Conversation

@kuangmi-bit

Copy link
Copy Markdown

Problem

When an inbound JSON-RPC frame carries "id": null with per-request _meta for protocol version 2026-07-28, the server panics with SIGSEGV (nil pointer dereference on initializeParams.ProtocolVersion).

The root cause is a two-step gap:

  1. validateRequestMeta returns initializeParams: nil, usesNewProtocol: true when req.IsCall() returns false (triggered by id: null).
  2. ServerSession.handle dereferences initializeParams.ProtocolVersion without checking for nil.

Fixes: #1043

Fix

One-line nil guard at server.go:1815, matching the pattern already used on line 1846:

- if validatedMeta.usesNewProtocol &&
+ if validatedMeta.usesNewProtocol && validatedMeta.initializeParams != nil &&

Test

Regression test exercises three methods (completion/complete, prompts/get, tools/call) with id: null + new-protocol _meta — all three previously panicked, now return gracefully.

go test ./mcp/ -run TestServerSessionHandle_NullIDWithNewProtocol_NoPanic -v
# PASS: 3/3 subtests, 0.00s

When a request carries id:null (IsCall() returns false),
validateRequestMeta returns initializeParams=nil but
usesNewProtocol=true. The subsequent protocol-version check
dereferences the nil pointer, causing SIGSEGV.

Add a nil guard matching the pattern already used at the
initialization check (line 1846).

Regression test exercises completion/complete, prompts/get,
and tools/call with id:null + new-protocol _meta — all three
previously panicked before the fix.

Fixes modelcontextprotocol#1043
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Server panics on id: null request with per-request protocol _meta

1 participant